package cn.flying.cloud.flow.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.flying.cloud.flow.entity.FwProcNode;

/**
 * BPMN节点表 Mapper 接口
 *
 * @author
 * @since 2024-09-20 10:45:05
 */
@Mapper
public interface FwProcNodeMapper {

    /**
     * 查询
     *
     * @param fwProcNode
     * @return
     */
    @Select("<script> " +
            "select " +
            "id, " +
            "proc_def_id, " +
            "proc_def_key, " +
            "node_id, " +
            "node_name, " +
            "node_type, " +
            "version, " +
            "remark, " +
            "created_by, " +
            "created_time, " +
            "updated_by, " +
            "updated_time, " +
            "tenant_id, " +
            "revision, " +
            "deleted " +
            "from " +
            "fw_proc_node" +
            "<where> " +
            "<if test='procDefId != null and procDefId != \"\"'> and proc_def_id_ = #{procDefId} </if>" +
            "<if test='procDefKey != null and procDefKey != \"\"'> and proc_def_key = #{procDefKey} </if>" +
            "<if test='tenantId != null and tenantId != \"\"'> and tenant_id = #{tenantId} </if>" +
            "<if test='deleted != null and deleted != \"\"'> and deleted = #{deleted} </if>" +
            "</where> " +
            "</script>")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "procDefId", column = "proc_def_id"),
            @Result(property = "procDefKey", column = "proc_def_key"),
            @Result(property = "nodeId", column = "node_id"),
            @Result(property = "nodeName", column = "node_name"),
            @Result(property = "nodeType", column = "node_type"),
            @Result(property = "version", column = "version"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "createdBy", column = "created_by"),
            @Result(property = "createdTime", column = "created_time"),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedTime", column = "updated_time"),
            @Result(property = "tenantId", column = "tenant_id"),
            @Result(property = "revision", column = "revision"),
            @Result(property = "deleted", column = "deleted")
    })
    List<FwProcNode> list(FwProcNode fwProcNode);

    /**
     * 插入
     *
     * @param fwProcNode 实体对象
     * @return
     */
    @Insert("insert into fw_proc_node (id, proc_def_id, proc_def_key, node_id, node_name, node_type, version, remark, created_by, created_time, updated_by, updated_time, tenant_id, revision, deleted) " +
            "values (#{id}, #{procDefId}, #{procDefKey}, #{nodeId}, #{nodeName}, #{nodeType}, #{version}, #{remark}, #{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime}, #{tenantId}, #{revision}, #{deleted}) ")
    int insert(FwProcNode fwProcNode);

    /**
     * 更新
     *
     * @param fwProcNode 实体对象
     * @return
     */
    @Update({
            "<script>" +
                    "update fw_proc_node " +
                    "<set> " +
                    "<if test='procDefId != null and procDefId != \"\"'>proc_def_id = #{procDefId}, </if>" +
                    "<if test='procDefKey != null and procDefKey != \"\"'>proc_def_key = #{procDefKey}, </if>" +
                    "<if test='nodeId != null and nodeId != \"\"'>node_id = #{nodeId}, </if>" +
                    "<if test='nodeName != null and nodeName != \"\"'>node_name = #{nodeName}, </if>" +
                    "<if test='nodeType != null and nodeType != \"\"'>node_type = #{nodeType}, </if>" +
                    "<if test='version != null and version != \"\"'>version = #{version}, </if>" +
                    "<if test='remark != null and remark != \"\"'>proc_def_key = #{remark}, </if>" +
                    "<if test='createdBy != null and createdBy != \"\"'>created_by = #{createdBy}, </if>" +
                    "<if test='createdTime != null'>created_time = #{createdTime}, </if>" +
                    "<if test='updatedBy != null and updatedBy != \"\"'>updated_by = #{updatedBy}, </if>" +
                    "<if test='updatedTime != null'>updated_time = #{updatedTime}, </if>" +
                    "<if test='tenantId != null and tenantId != \"\"'>tenant_id = #{tenantId}, </if>" +
                    "<if test='revision != null and revision != \"\"'>revision = #{revision}, </if>" +
                    "<if test='deleted != null and deleted != \"\"'>deleted = #{deleted}, </if>" +
                    "</set> " +
                    "where id = #{id} and tenant_id = #{tenantId} and revision = #{revision} " +
                    "</script>"
    })
    int update(FwProcNode fwProcNode);

    /**
     * 删除
     *
     * @param fwProcNode
     * @return
     */
    @Delete({
            "<script>" +
                    "delete fw_proc_node " +
                    "<where> " +
                    "<if test='id != null and id != \"\"'>and id = #{id} </if>" +
                    "<if test='procDefId != null and procDefId != \"\"'>and proc_def_id = #{procDefId} </if>" +
                    "<if test='procDefKey != null and procDefKey != \"\"'>and proc_def_key = #{procDefKey} </if>" +
                    "<if test='nodeId != null and nodeId != \"\"'>and node_id = #{nodeId} </if>" +
                    "<if test='nodeName != null and nodeName != \"\"'>and node_name = #{nodeName} </if>" +
                    "<if test='nodeType != null and nodeType != \"\"'>and node_type = #{nodeType} </if>" +
                    "<if test='version != null and version != \"\"'>and version = #{version} </if>" +
                    "<if test='remark != null and remark != \"\"'>and proc_def_key = #{remark} </if>" +
                    "<if test='createdBy != null and createdBy != \"\"'>and created_by = #{createdBy} </if>" +
                    "<if test='createdTime != null'>and created_time = #{createdTime} </if>" +
                    "<if test='updatedBy != null and updatedBy != \"\"'>and updated_by = #{updatedBy} </if>" +
                    "<if test='updatedTime != null'>and updated_time = #{updatedTime} </if>" +
                    "<if test='tenantId != null and tenantId != \"\"'>and tenant_id = #{tenantId} </if>" +
                    "<if test='revision != null and revision != \"\"'>and revision = #{revision} </if>" +
                    "<if test='deleted != null and deleted != \"\"'>and deleted = #{deleted} </if>" +
                    "</where> " +
                    "</script>"
    })
    int delete(FwProcNode fwProcNode);

}
